package com.sicilin.common.filter;

import net.sf.json.JSONObject;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class PrintUrlFilter implements Filter{
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;
//        String queryString = request.getQueryString() == null ? "":"?"+request.getQueryString();

        System.err.println(request.getMethod()+"--"+request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getRequestURI());
        if(!request.getParameterMap().isEmpty()) {
            JSONObject jsonObject = JSONObject.fromObject(request.getParameterMap());
            System.err.println("-- parameters:"+jsonObject.toString());
        }

        filterChain.doFilter(request,response);
    }

    public void destroy() {

    }
}
